import { ShallowReactive } from 'vue'
import { Textarea } from '@/components/ui/textarea'
import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input'
import { Switch } from '@/components/ui/switch'
import { Button } from '@/components/ui/button'
import { CheckboxIndicator, CheckboxRoot } from 'radix-vue'
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import SelectComponent from '@/components/vue-flow/nodes/selectComponent.vue'
import { selectReference, knowledgedict, dict,typesOptions } from '@/lib/dict'
import {ReferenceOption,Option} from '@/components/vue-flow/nodes/types/form-types'
import storeMap from '@/pina'
// import { Option } from 'lucide-vue-next'
export const useDynamicCom = (type: string,formItem: any,index:number,nodeType:string) => {
  switch (type) {
    case 'name':
      return {
        type: "Input",
        class: 'w-[150px]',
        placeholder: '请输入名称',
        modelValue: formItem['name'],
        disabled: nodeType=='module'?true:formItem.disabled,
        index,
        outputkey:type
      }
    case 'Label':
        return {
          type: "Label",
          index,
        }
    case 'type':
      return {
        type: "SelectComponent",
        Options: useGetOptions('types'),
        class: 'w-[129px]',
        modelValue: formItem[type],
        disabled: formItem.disabled,
        index,
        outputkey:type
      }
    case 'description':
      return {
        type: "Input",
        class: 'w-[200px]',
        modelValue: formItem[type],
        disabled: formItem.disabled,
        index,
        outputkey:type
      }
    case 'required':
      return {
        type: "Checkbox",
        modelValue: formItem[type],
        disabled: false,
        class:"flex-1",
        index,
        outputkey:type
      }
    case 'action':
      return {
        type: "MinusCircleIcon",
        modelValue: false,
        disabled: formItem.disabled,
        class:"h-4 w-4 text-gray-400",
        index,
        handelEvent: (storeId:string,nodeType?:string)=>{
          if(storeId=='useStartStore'){
            storeMap[storeId]().deleteItem(formItem[type])
          }else if(storeId=='useLLMStore'){
            console.log(formItem[type],'formItem[type]')
            storeMap[storeId]().deleteOutputItem(formItem[type])//删除output数据
          }
        }
      }
    default:
      return {
        type: Input,
        index,
        outputkey:type
      }
  }
}

export const useLLMDynamicCom = (type: string,formItem: any,index:number,Options:any) => {
  switch (type) {
    case 'name':
      return {
        type: "Input",
        class: 'w-[180px]',
        placeholder: '请输入名称',
        modelValue: formItem[type],
        index,
        outputkey:type
      }
    case 'Label':
        return {
          type: "Label",
          index,
        }
    case 'category':
      return {
        type: "SelectComponent",
        Options: useGetOptions('reference'),
        class: 'w-[100px] no-gap-radius-right',
        modelValue: formItem[type],
        index,
        outputkey:type,
        isTree:false,
      }
    case 'value':
      
      return formItem['category']=='1'?{
        type: "SelectComponent",
        Options:Options.value||[],
        class: 'w-2/5 no-gap-radius-left',
        placeholder:'请选择',
        modelValue: formItem[type],
        index,
        outputkey:type,
        isTree:true,
      }:{
        type: "Input",
        class: 'w-2/5 no-gap-radius-left',
        placeholder:'请选择',
        modelValue: formItem[type],
        index,
        outputkey:type
      }
    case 'action':
      return {
        type: "MinusCircleIcon",
        modelValue: false,
        class:"h-4 w-4 text-gray-400",
        index,
        handelEvent: (storeId:string,nodeType?:string)=>{
          console.log(storeId,'storeIdstoreId')
          storeMap[storeId]().deleteItem(formItem[type])
        }
      }
    default:
      return {
        type: Input,
        index,
        outputkey:type
      }
  }
}
export const useIfDynamicCom = (formItem: any,index:number,Options:any,priorityIndex:number,id:string):any => {
  const {left,right,relational} = formItem
  const leftObj ={
    type:'SelectComponent',
    Options,
    class: 'w-[100px]',
    modelValue: left['value'],
    ref:"",
    index,
    outputkey: "left.value",
    isTree:true,
  }
  const relationalObj ={
    type:'SelectComponent',
    Options:useGetOptions('conditions'),
    class: 'w-[100px]',
    modelValue: relational||'eq',
    index,
    outputkey: 'relational',
    isTree:false,
  }
  const rightObj:any =
  [{
    type:'SelectComponent',
    Options: useGetOptions('reference'),
    class: 'w-[70px] no-gap-radius-right',
    modelValue: right['category'],
    index,
    outputkey: "right.category",
    isTree:false,
  },
  {
    class: priorityIndex<2?'w-130 no-gap-radius-left':'w-[90px] no-gap-radius-left',
    type:'SelectComponent',
    Options,
    modelValue: right['value'],
    index,
    outputkey: "right.value",
    isTree:true,
  },
  {
    type: "MinusCircleIcon",
    modelValue: false,
    class:"h-4 w-4 text-gray-400",
    index,
    handelDeleceEvent: (storeId:string,index?:number,conditionsIndex?:number)=>{
      storeMap[storeId]().deleteItemCondition(index,conditionsIndex,id)
    }
  }]
  rightObj[1].type = right.category =='1'?rightObj[1].type ='SelectComponent':rightObj[1].type ='Input';
  const mergetItemObj = [leftObj,relationalObj].concat(rightObj)
  return mergetItemObj;
}
export const useGetOptions = (type?: string): {label: string
  value: string}[] => {
  switch (type) {
    case 'types':
      return [...typesOptions]
    case 'reference':
      return [...selectReference]
    case 'knowledge':
      return [...knowledgedict]
      case 'conditions':
        return [...dict]
    default:
      return [{
        label: '请选择',
        value: '',
      }]
  }
}


